import React, { useState } from "react";
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  UploadOutlined,
  UserOutlined,
  VideoCameraOutlined,
} from "@ant-design/icons";
import { Button, Layout, Menu, theme } from "antd";
import { Outlet, useNavigate } from "react-router-dom";
const { Header, Sider, Content } = Layout;

const Manage: React.FC = () => {
  const navigate = useNavigate();
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  const items = [
    {
      key: "/manage/homepage",
      icon: <UserOutlined />,
      label: "首页",
    },
    {
      key: "/manage/article",
      icon: <VideoCameraOutlined />,
      label: "文章",
      children: [
        {
          key: "/manage/article/publishing",
          label: "文章发布",
        },
        {
          key: "/manage/article/management",
          label: "文章管理",
        },
      ],
    },
    {
      key: "/manage/log",
      icon: <UploadOutlined />,
      label: "日志",
    },
    {
      key: "/manage/changeSkin",
      icon: <UploadOutlined />,
      label: "换肤",
    },
  ];
  return (
    <Layout style={{ minHeight: "100vh" }}>
      <Sider trigger={null} collapsible collapsed={collapsed}>
        <div className="demo-logo-vertical" />
        <Menu
          theme="dark"
          mode="inline"
          defaultSelectedKeys={["1"]}
          items={items}
          onSelect={(e) => {
            navigate(e.key);
          }}
        />
      </Sider>
      <Layout>
        <Header style={{ padding: 0, background: colorBgContainer }}>
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: "16px",
              width: 64,
              height: 64,
            }}
          />
          <Button onClick={() => navigate("/")}>返回主页</Button>
        </Header>
        <Content
          style={{
            margin: "24px 16px",
            padding: 13,
            minHeight: 280,
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
          <Outlet></Outlet>
        </Content>
      </Layout>
    </Layout>
  );
};

export default Manage;
